﻿using System.Web.Mvc;
using DNT.RavenQA.Core.Extensions;
using Raven.Client;

namespace DNT.RavenQA.Web.Infrastructure.Filters
{
    public class UnitOfWorkAttribute : ActionFilterAttribute
    {
        public IDocumentSession Session { get; set; }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.Exception.IsNull())
                Session.SaveChanges();

            base.OnActionExecuted(filterContext);
        }
    }
}